package xuhaijia.lanou3g.autohome.myself;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import xuhaijia.lanou3g.autohome.R;
import xuhaijia.lanou3g.autohome.base.NetTool;

/**
 * Created by 7 on 16/9/1.
 */
public class CollectionAdapter extends BaseAdapter {
    Context context;
    ArrayList<Collection> arrayList;
    NetTool mNetTool = new NetTool();

    public CollectionAdapter(Context context) {
        this.context = context;
    }

    public void setArrayList(ArrayList<Collection> arrayList) {
        this.arrayList = arrayList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return arrayList != null ? arrayList.size() :0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_collection , null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.title.setText(arrayList.get(position).getName());
        viewHolder.type.setText(arrayList.get(position).getType());
        viewHolder.price.setText(arrayList.get(position).getPrice());
        mNetTool.getImage(arrayList.get(position).getPicUrl() , viewHolder.iv);

        return convertView;
    }

    private class ViewHolder {
        ImageView iv;
        TextView title;
        TextView type;
        TextView price;
        public ViewHolder(View view) {
            iv = (ImageView) view.findViewById(R.id.item_collection_iv);
            title = (TextView) view.findViewById(R.id.item_collection_title);
            type = (TextView) view.findViewById(R.id.item_collection_type);
            price = (TextView) view.findViewById(R.id.item_collection_price);
        }
    }
}
